<template>
  <div class="ed-verify-box">
    <div>
      <el-input
        type="verify"
        :placeholder="placeholder"
        :value="value"
        v-on="$listeners"
      />
    </div>
    <div class="ed-verify-img">
      <img
        alt="点击切换"
        :src="src"
        @click="reload"
      >
    </div>
  </div>
</template>

<script>
export default {
  props: {
    // eslint-disable-next-line vue/require-default-prop
    url: {
      type: String,
      require: true
    },
    value: {
      type: [String, Number],
      default: null
    },
    placeholder: {
      type: String,
      default: '验证码'
    }
  },
  data () {
    const vm = this
    return {
      src: vm.url
    }
  },
  methods: {
    reload () {
      this.src = `${this.url}/?random=${Math.random()}`
    }
  }
}
</script>

<style scoped>
  .ed-verify-box {
    display: flex;
    flex: 1;
    flex-direction: column;
  }
  .ed-verify-img {
    margin: 10px 0;
  }
</style>
